package controllers

import (
	"cashew.com/cashew_common/configs"
	"cashew.com/cashew_task/services"
)

type UserController struct {
	BaseController
}

// 给活跃用户打标签
func (c *UserController) TagActiveUsers() {

	activeDuration, _ := c.GetInt("active_duration")

	if activeDuration == 0 {
		// 多10秒冗余时间，防止时间不连续导致遗漏数据
		activeDuration = 3600 + 10
	}

	workServerName := configs.WorkServerName
	if workServerName == "" {
		workServerName = "cashew" // 默认值
	}

	var tagActiveUsersFunc func(int) error
	switch workServerName {
	case "cashew":
		tagActiveUsersFunc = services.TagActiveUsers
	case "maoyin":
		tagActiveUsersFunc = services.TagMaoyinActiveUsers
	default:
		// 报错
		c.Error("Invalid work server name: %s", workServerName)
		c.buildSystemErrorResult()
		return
	}

	var err error
	// 调用对应的服务方法
	err = tagActiveUsersFunc(activeDuration)
	if err != nil {
		// 记录详细错误日志
		c.Error("Failed to tag active users: %v", err)
		c.buildSystemErrorResult()
		return
	}

	// 初始化结果
	c.initResult()
}

func (c *UserController) TagAllUsers() {

}

func (c *UserController) SendUserOfflineLiveMessage() {
	// 发送离线直播消息
	services.SendUserOfflineLiveMessage()
	c.initResult()
}
